Variational quantum support vector machine based on Γ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\Gamma $$\end{document} matrix expansion and variational universal-quantum-state generator

We analyze a binary classification problem by using a support vector machine based on variational quantum-circuit model. We propose to solve a linear equation of the support vector machine by using a Γ\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$\Gamma $$\end{document} matrix expansion. In addition, it is shown that an arbitrary quantum state is prepared by optimizing a universal quantum circuit representing an arbitrary U(2N)\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$U(2^N)$$\end{document} based on the steepest descent method. It may be a quantum generalization of Field-Programmable-Gate Array (FPGA).

Variational quantum support vector machine based on Ŵ matrix expansion and variational universal-quantum-state generator

Motohiko Ezawa
We analyze a binary classification problem by using a support vector machine based on variational quantum-circuit model. We propose to solve a linear equation of the support vector machine by using a Ŵ matrix expansion. In addition, it is shown that an arbitrary quantum state is prepared by optimizing a universal quantum circuit representing an arbitrary U(2 N ) based on the steepest descent method. It may be a quantum generalization of Field-Programmable-Gate Array (FPGA).
Quantum computation is a hottest topic in contemporary physics [1][2][3] . An efficient application of quantum computations is machine learning, which is called quantum machine learning [4][5][6][7][8][9][10][11][12][13][14][15][16][17] . A support vector machine is one of the most fundamental algorithms for machine learning 18,22,23 , which classifies data into two classes by a hyperplane. A support vector machine (SVM) is a computer algorithm that learns by examples to assign labels to objects. It is a typical method to solve a binary-classification problem 18 . The optimal hyperplane is determined by an associated linear equation F|ψ in � = |ψ out � , where F and |ψ out � are given. A quantum support vector machine solves this linear equation by a quantum computer 10,13,24 . Usually, the linear equation is solved by the Harrow-Hassidim-Lloyd (HHL) algorithm 25 . However, this algorithm requires many quantum gates. Thus, the HHL algorithm is hard to be executed by using a near-term quantum computer. Actually, this algorithm has experimentally been verified only for two and three qubits [26][27][28] . In addition, it requires a unitary operator to execute e iFt , which is quite hard to be implemented. The Kernel based SVM implementation based on the quantum is reported [19][20][21] .
The number of qubits in current quantum computers is restricted. Variational quantum algorithms are appropriate for these small-qubit quantum computers, which use both quantum computers and classical computers. Various methods have been proposed such as Quantum Approximate Optimization Algorithm (QAOA) 29 , variational eigenvalue solver 30 , quantum circuit learning 31 and quantum linear solver 32,33 . We use wave functions with variational parameters in QAOA, which are optimized by minimizing the expectation value of the Hamiltonian. A quantum circuit has variational parameters in quantum circuit learning 31 , which are optimized by minimizing a certain cost function. A quantum linear solver solves a linear equation by variational ansatz 32,33 . The simplest method of the optimization is a steepest-descent method.
In this paper, we present a variational method for a quantum support vector machine by solving an associated linear equation based on variational quantum circuit learning. We propose a method to expand the matrix F by the Ŵ matrices, which gives simple quantum circuits. We also propose a variational method to construct an arbitrary state by using a universal quantum circuit to represent an arbitrary unitary matrix U(2 N ) . We prepare various internal parameters for a universal quantum circuit, which we optimize by minimizing a certain cost function. Our circuit is capable to determine the unitary transformation U satisfying U|ψ initial � = |ψ final � with arbitrary given states |ψ initial � and |ψ final � . It will be a quantum generalization of field-programmable-gate array (FPGA), which may execute arbitrary outputs with arbitrary inputs. separating data into two classes with the use of a support vector machine. We set for red points and for blue points. These conditions are implemented by introducing a function which assigns f (x) = 1 to red points and f (x) = −1 to blue points. In order to determine ω 0 and ω for a given set of data x j , we introduce real numbers α j by A support vector machine enables us to determine ω 0 and α j by solving the linear equation where y i = f (x i ) = ±1 , and F is a (M + 1) × (M + 1) matrix given by Here, is a Kernel matrix, and γ is a certain fixed constant which assures the existence of the solution of the linear equation (6) even when the red and blue points are slightly inseparable. Note that γ → ∞ corresponds to the hard margin condition. Details of the derivation of Eq. (6) are given in Method A.
Quantum linear solver based on Ŵ matrix expansion. We solve the linear equation (6) by a quantum computer. In general, we solve a linear equation for an arbitrary given non-unitary matrix F and an arbitrary given state |ψ out � . Here, the coefficient c is introduced to preserve the norm of the state, and it is given by F|ψ in � = c|ψ out �, The vertical axis is the log 10 E cost . The horizontal axis is the variational step number. We have used r = 2 , ξ 1 = 0.001 and ξ 2 = 0.0005 and γ = 1 . We have runed simulations ten times, where each simulation is plotted in different color. (c) The saturated value of the cost function log 10 E opt as a function of ξ 2 ranging 10 −1 ≤ ξ 2 ≤ 10 −5 for various ξ 1 . The green dots indicates ξ 1 = 0.0001 , black dots indicates ξ 1 = 0.001 , magenta dots indicates ξ 1 = 0.01 and cyan dots indicates ξ 1 = 0.1. Then, a unitary matrix associated with F is uniquely obtained by e iHt . Nevertheless, it requires many quantum gates. In addition, it is a nontrivial problem to implement e iHt .

Scientific Reports
Recently, variational methods have been proposed 32 to solve the linear equation (9). In one of the methods, the matrix F is expanded in terms of some unitary matrices U j as In general, a complicated quantum circuit is necessary to determine the coefficient c j .
We start with a trial state |ψ in � to determine the state |ψ in � . Application of each unitary matrix to this state is efficiently done by a quantum computer, U j |ψ in � = |ψ (j) out � , and we obtain where |ψ out � is an approximation of the given state |ψ out � . We tune a trial state |ψ in � by a variational method so as to minimize the cost function 32 which measures the similarity between the approximate state |ψ out � and the state |ψ out � in (9). We have 0 ≤ E cost ≤ 1 , where E cost = 0 for the exact solution. The merit of this cost function is that the inner product is naturally calculated by a quantum computer. Let the dimension of the matrix F be 2 N . It is enough to use N satisfying 2 N−1 < D ≤ 2 N without loss of generality by adding trivial 2 N − D components to the linear equation. We propose to expand the matrix F by the gamma matrices Ŵ j as with where α = 0, x, y and z.
The merit of our method is that it is straightforward to determine c j by the well-known formula In order to construct a quantum circuit to calculate c j , we express the matrix F by column vectors as Then c j is given by where the subscript q denotes the ( q + 1)-th component of Ŵ j f q . We have introduced a notation q � ≡ |n 1 n 2 · · · n N � with n i = 0, 1 , where q is the decimal representation of the binary number n 1 n 2 · · · n N . See explicit examples for one and two qubits in Method B. The state q ≡ |n 1 n 2 · · · n N � is generated as follows. We prepare the NOT gates σ (i) x for the i-th qubit if n i = 1 . Using all these NOT gates we define We act it on the initial state |0�� and obtain (10) c = �ψ in |F † F|ψ in �. Once we have c j , the final state is obtained by applying Ŵ j to |ψ in � and taking sum over j, which leads to The implementation of the Ŵ matrix is straightforward in quantum circuit, because the Ŵ matrix is composed of the Pauli sigma matrices, as shown in Fig. 2.
Steepest-descent method. One of the most common approaches to optimization is the steepest-descent method, where we make iterative steps in directions indicated by the gradient 34 . We may use this method to find an optimal trial state |ψ in � closest to the state |ψ in � . To determine the gradient, we calculate the difference of the cost function E cost when we slightly change the trial state |ψ in (t)� at step t by the amount of �|ψ in (t)� as We explain how to construct |ψ in (t)� by a quantum circuit soon later; See Eq. (33). Then, we renew the state as where we use an exponential function for η t , We choose appropriate constants ξ 1 and ξ 2 for an efficient search of the optimal solution, whose explicit examples are given in the caption of Fig. 1b. We stop the renewal of the variational step when the difference �|ψ in (t)� becomes sufficiently small, which gives the optimal state of the linear equation (9). In the numerical simulation, we discretize the time step with a fixed t . We add a small value η(n�t) in the p-th component of the trial state |ψ (p) in (t)� at the n step where δ (p) denotes a unit vector where only the p component is 1 and the other components are zero. Then, we calculate the costfunction By running p from 1 to 2 N , we obtain a vector E (p) cost ((n + 1)�t) , whose p-th component is E (p) cost ((n + 1)�t) . Then, the gradient is numerically obtained as

Figure 2.
Quantum circuits determining c j . We show an example with (a) We iterate this process so that �E cost (n + 1) becomes sufficiently small. We denote the saturated cost function E opt . It depends on the choice of ξ 1 and ξ 2 in Eq. (27). We show log 10 E opt as a function of ξ 2 for various ξ 1 in Fig. 1c. There are some features. First, E opt is small for small ξ 1 . Namely, we need to choose small ξ 1 in order to obtain a good solution. On the other hand, the required step increases for small ξ 1 . It is natural that small ξ 1 means that the step size is small. The required step number is antiproportional to ξ 1 . Second, there is a critical value to obtain a good solution as a function of ξ 2 for a fixed value of ξ 1 . We find that it is necessary to set ξ 2 < 10 −3 .
A comment is in order. The cost function does not become zero although it becomes very small. It means that the solution is trapped by a local minimum and does not reach the exact solution. It is a general feature of variational algorithms, where we cannot obtain the exact solution. However, the exact solution is unnecessary in many cases including machine learnings. Actually, the classification shown in Fig. 1a is well done.
Variational universal-quantum-state generator. In order to construct the trial state |ψ in (t)� , it is necessary to prepare an arbitrary state |ψ� by a quantum circuit. Alternatively, we need such a unitary transformation U that It is known that any unitary transformation is done by a sequential application of the Hadamard, the π/4 phaseshift and the CNOT gates 35,36 . Indeed, an arbitrary unitary matrix is decomposable into a sequential application of quantum gates 35,36 , each of which is constructed as a universal quantum circuit systematically [37][38][39][40][41][42] . Universal quantum circuits have so far been demonstrated experimentally for two and three qubits [43][44][45][46] .
We may use a variational method to construct U satisfying Eq. (33). Quantum circuit learning is a variational method 31 , where angle variables θ i are used as variational parameters in a quantum circuit U, and the cost function is optimized by tuning θ i . We propose to use a quantum circuit learning for a universal quantum circuit. We show that an arbitrary state |ψ(θ i )� can be generated by tuning U(θ i ) starting from the initial state |0�� as We adjust θ i by minimizing the cost function which is the same as that of the variational quantum support vector machine. We present explicit examples of universal quantum circuits for one, two and three qubits in Method C.
Quantum field-programmable-gate array. We next consider a problem to find a unitary transformation U ini-fin which maps an arbitrary initial state |ψ initial � to an arbitrary final state |ψ final �, Since we can generate an arbitrary unitary matrix as in Eq. (33), it is possible to generate such matrices U ini and U fin that Then, Eq. (36) is solved as An FPGA is a classical integrated circuit [47][48][49][50] , which can be programmable by a customer or a designer after manufacturing in a factory. An FPGA executes any classical algorithms. On the other hand, our variational universal quantum-state generator creates an arbitrary quantum state. We program by using the variational parameters θ i . In this sense, the above quantum circuit may be considered as a quantum generalization of FPGA, which is a quantum FPGA (q-FPGA).
We show explicitly how the cost function is renewed for each variational step in the case of two-and threequbit universal quantum circuits in Fig. 3, where we have generated the initial and the final states randomly. We optimize 15 parameters θ i for two-qubit universal quantum circuits and 82 parameters θ i for three-qubit universal quantum circuits. We find that U ini-fin is well determined by variational method as in Fig.3.
Variational quantum support vector machine. We demonstrate a binary classification problem in two dimensions based on the support vector machine. We prepare a data set, where red points have a distribution around (r cos �, r sin �) with variance r, while blue points have a distribution around (−r cos �, −r sin �) with |ψ (p) in ((n + 1)�t)� = |ψ (p) in (n�t)� + �E cost (n + 1). www.nature.com/scientificreports/ variance r. We assume the Gaussian normal distribution. We choose randomly. We note that there are some overlaps between the red and blue points, which is the soft margin model.
As an example, we show the distribution of red and blue points and the lines obtained by the variational method marked in cyan and by the direct solution of (6) marked in magenta in Fig. 1a. They agrees well with one another, where both of the lines well separate red and blue points. We have prepared 31 red points and 32 blue points, and used six qubits.

Discussion
Efficiency. The original proposal 10  N qubit can represent 2 N−1 < N D M ≤ 2 N . Hence, the required number of qubits is N = log (N D M) . We need 4 N − 1 quantum gates for an exact preparation of a universal quantum state. On the other hand, a hardwareefficient universal quantum circuit prepares an approximate universal quantum state by using the order of 4N quantum gates [52][53][54] . We need N quantum gates for the execution of U (q) X and Ŵ j , separately. We need 4 N + 2N − 1 quantum gates for exact preparation and 6N for approximate preparation. In machine learning, the exact solution is unnecessary. Thus, 6N quantum gates are enough.
On the other hand, the accuracy is independent of the number of required quantum gates. It is determined by ξ 1 as shown in new Fig.1c. Radial basis function. In this paper, we have used the linear Kernel function (8), which is efficient to classify data points linearly. However, it is not sufficient to classify data points which are not separated by the linear function. The radial basis function 55,56 is given by with a free parameter σ . It is used for a nonlinear classification 57 . It is known 58,59 that the depth of a quantum is linear to the dimension of the feature space N.

Conclusion
We have proposed that the matrix F is efficiently inputted into a quantum computer by using the Ŵ-matrix expansion method. There are many ways to use a matrix in a quantum computer such as linear regression and principal component analysis. Our method will be applicable to these cases.
Although it is possible to obtain the exact solution for the linear equation by the HHL algorithm, it requires many gates. On the other hand, it is often hard to obtain the exact solution by variational methods since trial functions may be trapped to a local minimum. However, this problem is not serious for the machine learning problem because it is more important to obtain an approximate solution efficiently rather than an exact solution by using many gates. Indeed, our optimized hyperplane also well separates red and blue points as shown in Fig. 1a.
In order to classify M data, we need to prepare log 2 M qubits. It is hard to execute a large number of data points by current quantum computers. Recently, it is shown that electric circuits may simulate universal quantum gates 60-62 based on the fact that the Kirchhoff law is rewritten in the form of the Schrödinger equation 63 . Our variational algorithm will be simulated by using them.

Support vector machine.
A support vector machine is an algorithm for supervised learning 18,22,23 . We first prepare a set of training data, where each point is marked either in red or blue. Then, we determine a hyperplane separating red and blue points. After learning, input data are classified into red or blue by comparing the input Figure 3. Evolution of the cost function for (a) two qubits and (b) three qubits. The vertical axis is the log 10 E cost . The horizontal axis is the number of variational steps. We use c 1 = 0.005 and c 2 = 0.005 for both the two-and three-qubit universal quantum circuits. We prepare random initial and final states, where we have runed simulations ten times. Each simulation is plotted in different color. www.nature.com/scientificreports/ data with the hyperplane. The support vector machine maximizes a margin, which is a distance between the hyperplane and data points. If red and blue points are perfectly separated by the hyperplane, it is called a hard margin problem (Fig.4a). Otherwise, it is called a soft margin problem (Fig.4b).
We minimize the distance d j between a data point x j and the hyperplane given by We define support vectors x as the closest points to the hyperplane. There is such a vector in each side of the hyperplane, as shown in Fig. 4a. This is the origin of the name of the support vector machine. Without loss of generality, we set for the support vectors, because the hyperplane is present at the equidistance of two closest data points and because it is possible to set the magnitude of |ω · x + ω 0 | to be 1 by scaling ω and ω 0 . Then, we maximize the distance which is identical to minimize |ω|. First, we consider the hard margin problem, where red and blue points are perfectly separable. All red points satisfy ω · x j + ω 0 > 1 and all blue points satisfy ω · x j + ω 0 < −1 . We introduce variables y j , where y j = 1 for red points and y j = −1 for blue points. Using them, the condition is rewritten as for each j. The problem is reduced to find the minimum of |ω| 2 under the above inequalities. The optimization under inequality conditions is done by the Lagrange multiplier method with the Karush-Kuhn-Tucker condition 64 . It is expressed in terms of the Lagrangian as where β j are Lagrange multipliers to ensure the constraints.
For the soft margin case, we cannot separate two classes exactly. In order to treat this case, we introduce slack variables ξ j satisfying and redefine the cost function as Here, γ = ∞ corresponds to the hard margin. The second term represents the penalty for some of data points to have crossed over the hyperplane. The Lagrangian is modified as We may solve these equations to determine ω and ν j as from (48), and from (50). Inserting them into (51), we find Since y 2 j = 1 , it is rewritten as Since β j appears always in a pair with y j , we introduce a new variable defined by and we define the Kernel matrix K ij as Then, ω 0 and α j are obtained by solving linear equations which are summarized as which is Eq. (6) in the main text. Finally, ω is determined by Ŵ matrix expansion. We explicitly show how to calculate c j in (17) based on the Ŵ matrix expansion for the one and two qubits.
One qubit. We show an explicit example of the Ŵ -matrix expansion for one qubit. One qubit is represented by a 2 × 2 matrix, The column vectors are explicitly given by The coefficient c j in (17) is calculated as Two qubits. Next, we show an explicit example of the Ŵ-matrix expansion for two qubits. Two qubits are represented by a 4 × 4 matrix, The column vectors are explicitly given by The coefficient c j in (17) is calculated as (65) One-qubit universal quantum circuit. The single-qubit rotation gates are defined by The one-qubit universal quantum circuit is constructed as We show a quantum circuit in Fig. 5a. There are three variational parameters. It is obvious that an arbitrary state is realized starting from the state |0� as Two-qubit universal quantum circuit. The two-qubit universal quantum circuit is constructed as 43 where the entangling two-qubit gate is defined by 43 The two-qubits universal quantum circuit contains 15 variational parameters. We show a quantum circuit in Fig. 5b.
Three-qubit universal quantum circuit. The three-qubit universal quantum circuit is constructed as where U (1) C , and U D are one-qubit universal quantum circuits, while U A , U C , and U D are twoqubit universal quantum circuit and (78)   42 . The three-qubits universal quantum circuit contains 82 variational parameters. We show a quantum circuit in Fig. 5c.
Multi-qubit universal quantum circuit. General multi-qubit universal quantum circuit is constructed in Ref. 39 . The minimum numbers of variational parameters are 4 N − 1 for N-qubit unicersal quantum circuits. However, we need more variational parameters in the currently known algorithm for N ≥ 3. Actually, multi-qubit universal quantum circuits are well approximated by the hardware-efficient quantum circuit [52][53][54] . They are constructed as with the use of the single qubit rotation and the CNOT gates where U n→n+1 CROT stands for the controlled rotation gate with the controlled qubit being n and the target qubit being n + 1 . We need the order of 4N quantum gates for N-qubit universal quantum circuits. We show an example of the hardware-efficient quantum circuit with N = 4 in Fig. 6.
In addition, an ansatz based on the restricted Boltzmann machine requires N 2 quantum gates, while a unitarycoupled cluster ansatz requires N 4 quantum gates 16,34 . Simulations. All of the numerical calculations are carried out by Mathematica.